package com.skivingcloud.report.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.report.entity.ReportFormsDatasource;
import com.skivingcloud.report.mapper.ReportFormsDatasourceMapper;
import com.skivingcloud.report.service.ReportFormsDatasourceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * 填报报表绑定的填报数据源 服务层实现。
 *
 * @author skivingcloud
 * @since 2024-11-07
 */
@Service
public class ReportFormsDatasourceServiceImpl extends ServiceImpl<ReportFormsDatasourceMapper, ReportFormsDatasource> implements ReportFormsDatasourceService {

    /**
     * 分页查询填报报表绑定的填报数据源
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<ReportFormsDatasource> queryByPage(PageParameter<ReportFormsDatasource> parameter){
        Page<ReportFormsDatasource> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(ReportFormsDatasource::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getTplId())) {
                queryWrapper.and(ReportFormsDatasource::getTplId).like(parameter.getParam().getTplId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getSheetId())) {
                queryWrapper.and(ReportFormsDatasource::getSheetId).like(parameter.getParam().getSheetId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getName())) {
                queryWrapper.and(ReportFormsDatasource::getName).like(parameter.getParam().getName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDatasourceId())) {
                queryWrapper.and(ReportFormsDatasource::getDatasourceId).like(parameter.getParam().getDatasourceId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getTableName())) {
                queryWrapper.and(ReportFormsDatasource::getTableName).like(parameter.getParam().getTableName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCreator())) {
                queryWrapper.and(ReportFormsDatasource::getCreator).like(parameter.getParam().getCreator());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getUpdater())) {
                queryWrapper.and(ReportFormsDatasource::getUpdater).like(parameter.getParam().getUpdater());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDelFlag())) {
                queryWrapper.and(ReportFormsDatasource::getDelFlag).like(parameter.getParam().getDelFlag());
            }
        }
        return this.page(page, queryWrapper);
    }
}
